/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.st.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jeesite.modules.st.entity.StWarehousePositionSetting;
import com.jeesite.modules.st.service.StWarehousePositionSettingService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.st.entity.StWarehouseInventory;
import com.jeesite.modules.st.service.StWarehouseInventoryService;

import java.util.List;

/**
 * 实时库存Controller
 * @author HOHD
 * @version 2020-12-16
 */
@Controller
@RequestMapping(value = "${adminPath}/st/stWarehouseInventory")
public class StWarehouseInventoryController extends BaseController {

	@Autowired
	private StWarehouseInventoryService stWarehouseInventoryService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public StWarehouseInventory get(String id, boolean isNewRecord) {
		return stWarehouseInventoryService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("st:stWarehouseInventory:view")
	@RequestMapping(value = {"list", ""})
	public String list(StWarehouseInventory stWarehouseInventory, Model model) {
		model.addAttribute("stWarehouseInventory", stWarehouseInventory);
		return "modules/st/stWarehouseInventoryList";
	}
	@Autowired
	StWarehousePositionSettingService stWarehousePositionSettingService;
	@RequiresPermissions("st:stWarehouseInventory:view")
	@RequestMapping(value = {"time"})
	public String time(StWarehouseInventory stWarehouseInventory, Model model) {
		model.addAttribute("stWarehouseInventory", stWarehouseInventory);
		List<StWarehousePositionSetting> list = stWarehousePositionSettingService.findList(new StWarehousePositionSetting());
		model.addAttribute("list", list);
		return "modules/st/stWarehouseInventoryList-time";
	}
	@RequiresPermissions("st:stWarehouseInventory:view")
	@RequestMapping(value = {"listAll"})
	public String listAll(StWarehouseInventory stWarehouseInventory, Model model) {
		model.addAttribute("stWarehouseInventory", stWarehouseInventory);
		List<StWarehousePositionSetting> list = stWarehousePositionSettingService.findList(new StWarehousePositionSetting());
		model.addAttribute("list", list);
		return "modules/st/stWarehouseInventoryList-list-all";
	}

	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("st:stWarehouseInventory:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<StWarehouseInventory> listData(StWarehouseInventory stWarehouseInventory, HttpServletRequest request, HttpServletResponse response) {
		stWarehouseInventory.setPage(new Page<>(request, response));
		Page<StWarehouseInventory> page = stWarehouseInventoryService.findPage(stWarehouseInventory);
		return page;
	}
	@RequiresPermissions("st:stWarehouseInventory:view")
	@RequestMapping(value = "listNumber")
	@ResponseBody
	public Page<StWarehouseInventory> listNumber(StWarehouseInventory stWarehouseInventory, HttpServletRequest request, HttpServletResponse response) {
		stWarehouseInventory.setPage(new Page<>(request, response));
		Page<StWarehouseInventory> page = (Page<StWarehouseInventory>) stWarehouseInventory.getPage();
		boolean isDetail = !stWarehouseInventory.getDetail().equals("0");
		List<StWarehouseInventory> warehouseNumber = stWarehouseInventoryService.getWarehouseNumber(isDetail, null);
		page.setList(warehouseNumber);
		return page;
	}
	@RequiresPermissions("st:stWarehouseInventory:view")
	@RequestMapping(value = "listAllData")
	@ResponseBody
	public Page<StWarehouseInventory> listAllData(StWarehouseInventory stWarehouseInventory, HttpServletRequest request, HttpServletResponse response) {
		stWarehouseInventory.setPage(new Page<>(request, response));
		Page<StWarehouseInventory> page = (Page<StWarehouseInventory>) stWarehouseInventory.getPage();
		boolean isDetail = !stWarehouseInventory.getDetail().equals("0");
		List<StWarehouseInventory> warehouseNumberAll = stWarehouseInventoryService.getGoodsNumber(stWarehouseInventory);
		page.setList(warehouseNumberAll);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("st:stWarehouseInventory:view")
	@RequestMapping(value = "form")
	public String form(StWarehouseInventory stWarehouseInventory, Model model) {
		model.addAttribute("stWarehouseInventory", stWarehouseInventory);
		return "modules/st/stWarehouseInventoryForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("st:stWarehouseInventory:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated StWarehouseInventory stWarehouseInventory) {
		stWarehouseInventoryService.save(stWarehouseInventory);
		return renderResult(Global.TRUE, text("保存实时库存成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("st:stWarehouseInventory:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(StWarehouseInventory stWarehouseInventory) {
		stWarehouseInventoryService.delete(stWarehouseInventory);
		return renderResult(Global.TRUE, text("删除实时库存成功！"));
	}
	
}